package com.magicalcoder.pigeontest.spring.server.spring;

import com.magicalcoder.pigeon.common.callback.NettyStartSuccessCallback;
import com.magicalcoder.pigeon.server.PigeonNettyServer;
import com.magicalcoder.pigeontest.service.AdminUserService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by hedongyu on 2017/7/12.
 */
public class ServerStart {
    //args : port
    public static void main(String[] args) throws InterruptedException {
        int port = Integer.valueOf(args[0]);
//        int port = 8880;//一个端口号肯定对应一种service service可能包含很多java service
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath*:applicationContext.xml");
        System.out.println("start...");
        AdminUserService adminUserService = ctx.getBean(AdminUserService.class);
        Map<String,Object> kv = new HashMap<>();
        kv.put(AdminUserService.class.getName(),adminUserService);


        PigeonNettyServer server = new PigeonNettyServer(kv);
        server.start(port, new NettyStartSuccessCallback() {
            @Override
            public void call() {
                System.out.println("success");
            }
        });
    }
}
